//
//  DrivateTutorDetailViewController.m
//  Edumap
//
//  Created by 辰领科技 on 16/7/21.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "DrivateTutorDetailViewController.h"
#import "DrivateTutorDetailTableViewCell.h"
#import "MakeSureTheOrderViewController.h"
#import "CertificationQualificationViewController.h"
#import "AttributeView.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
#import "PersonalShowCollectionViewCell.h"
#import "PersonalShowViewController.h"
#import "NavPointAnnotation.h"
#import "SharePopView.h"
#import "AddOrDeleteView.h"


static NSString * CellIdentifier = @"DrivateTutorDetailTableViewCell";
static NSString * collectionIdentifier = @"PersonalShowCollectionViewCell";

@interface DrivateTutorDetailViewController ()
<UITableViewDelegate,UITableViewDataSource,BestScrollViewDelegate,BestScrollViewDatasource,UICollectionViewDataSource,UICollectionViewDelegate,MWPhotoBrowserDelegate>{
    NSInteger _totle;
}
@property (nonatomic,assign)   NSInteger    pageNO;


@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UIImageView *TeachersHeaderImage;//教师头像
@property (strong, nonatomic) IBOutlet UILabel *TeachersNameLabel;//教师名字
@property (strong, nonatomic) IBOutlet UILabel *TeachersTypeLabel;//教师课程
@property (strong, nonatomic) IBOutlet UILabel *moneyLabel;//价格
@property (strong, nonatomic) IBOutlet UIButton *distanceButton;//距离
@property (strong, nonatomic) IBOutlet UILabel *timeLabel;//总共时长
@property(nonatomic,assign)NSInteger number;
@property (strong, nonatomic) IBOutlet UILabel *addressLabel;//联系地址
@property (strong, nonatomic) IBOutlet UILabel *SelfAssessmentLabel;//自我评价

@property (strong, nonatomic) IBOutlet UIView *PersonalShowView;//个人展示View


@property (strong, nonatomic) IBOutlet UIView *GoodAtView;//个人擅长View
@property (strong, nonatomic) IBOutlet UICollectionView *collectView;

@property (strong, nonatomic) IBOutlet UILabel *one;
@property (strong, nonatomic) IBOutlet UILabel *two;
@property (strong, nonatomic) IBOutlet UILabel *three;
@property (strong, nonatomic) IBOutlet UILabel *four;
@property (strong, nonatomic) IBOutlet UILabel *five;
@property (strong, nonatomic) IBOutlet UILabel *six;

@property (strong, nonatomic) IBOutlet UIView *IntroductionView;//教师简介
@property (strong, nonatomic) IBOutlet UILabel *IntroductionLabel;

@property (strong, nonatomic) IBOutlet UIView *evaluationView;//评价View
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *totalMoney;//总计

@property (strong, nonatomic) IBOutlet UIButton *BGbutton;


@property (strong, nonatomic) IBOutlet UIButton *collectionButton;
@property (strong, nonatomic) IBOutlet UIView *collectionView;
@property (strong, nonatomic) IBOutlet UILabel *collectionLabel;
@property (strong, nonatomic) IBOutlet UIButton *returnButton;

@property (strong, nonatomic)  NSDictionary *TutorsDetailsDic;
@property (strong, nonatomic)  NSMutableArray *tableViewArray;


@property (nonatomic,strong)  BestScrollView *headerScroll;//滚动栏
@property (nonatomic,strong)  NSMutableArray  *imageArray;

@property(nonatomic,strong)NSArray * showArray;

@property (strong, nonatomic) IBOutlet UIButton *unfoldButton;
@property (nonatomic,strong) NSString *mstoContent;

@property(nonatomic,assign)CGFloat lat;
@property(nonatomic,assign)CGFloat lng;

@property(nonatomic,strong)NSMutableArray * photos;
@property(nonatomic,strong)MWPhotoBrowser * browser;

@end

@implementation DrivateTutorDetailViewController


- (void)viewDidDisappear:(BOOL)animated{
    _backBlock();
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //状态栏文字颜色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self clearMapView];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    _photos = [NSMutableArray array];
    _imageArray = [NSMutableArray array];
    _tableViewArray = [NSMutableArray array];
    _pageNO = 1;
    _number = 1;
    [self initViewLayout];
    [self TutorsDetails];
    [self addRefreshing];
    [self PersonalShow];
    [self initNavgationMap];
}

#pragma mark  地图导航实例化--=========================================
- (void)initNavgationMap{
    [self initMapView];
    
    [self initNaviManager];
    
    [self initIFlySpeech];
    //导航控制器
    [self initNaviViewController];
    
    [self configMapView];
    
}
- (void)configMapView
{
    self.mapView.delegate = self;
    self.mapView.showsCompass= NO;
    self.mapView.showsScale = NO;
    self.mapView.showsUserLocation = YES;
}
- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.collectionView];
    [self adaptiveViewLayout:self.scroview];
    [self adaptiveViewLayout:self.PersonalShowView];
    [self adaptiveViewLayout:self.GoodAtView];
    [self adaptiveViewLayout:self.IntroductionView];
    [self adaptiveViewLayout:self.evaluationView];
    
    _scroview.contentSize = flexibleSize(CGSizeMake(0, _evaluationView.frame.origin.y+_evaluationView.frame.size.height), NO);
    
    //加减数量
    AddOrDeleteView * addOrDeleteView = [[AddOrDeleteView alloc]initWithFrame:flexibleFrame(CGRectMake(59, 262, 115, 30), NO) complect:^(NSInteger num) {
        _number = num;
        _timeLabel.text = [NSString stringWithFormat:@"共%ld小时",(long)num];
        
        CGFloat price = [[NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpPrice"]]floatValue];
        _totalMoney.text = [NSString stringWithFormat:@"￥%.2f",price*num];
    }];
    [self.scroview addSubview:addOrDeleteView];
    
    [_tableView registerNib:[UINib nibWithNibName:CellIdentifier bundle:nil] forCellReuseIdentifier:CellIdentifier];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    
    self.collectionView.layer.cornerRadius = 5*VerticalRatio();
    self.returnButton.layer.cornerRadius = 5*VerticalRatio();
    self.TeachersHeaderImage.layer.masksToBounds = YES;
    self.TeachersHeaderImage.layer.cornerRadius = 25*VerticalRatio();
    
    //广告栏
    _headerScroll=[[BestScrollView alloc]  initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 177), NO)];
    [self.scroview insertSubview:_headerScroll belowSubview:_collectionButton];

    UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    self.collectView.collectionViewLayout = flowLayout;
    
    
    [self.collectView registerNib:[UINib nibWithNibName:collectionIdentifier bundle:nil] forCellWithReuseIdentifier:collectionIdentifier];
    self.collectView.delegate = self;
    self.collectView.dataSource = self;
    self.collectView.backgroundColor = [UIColor whiteColor];
    
    _browser = [[MWPhotoBrowser alloc] init];
    
    // Set options
    _browser.displayActionButton = YES; // Show action button to allow sharing, copying, etc (defaults to YES)
    _browser.displayNavArrows = NO; // Whether to display left and right nav arrows on toolbar (defaults to NO)
    _browser.displaySelectionButtons = NO; // Whether selection buttons are shown on each image (defaults to NO)
    _browser.zoomPhotosToFill = YES; // Images that almost fill the screen will be initially zoomed to fill (defaults to YES)
    _browser.alwaysShowControls = NO; // Allows to control whether the bars and controls are always visible or whether they fade away to show the photo full (defaults to NO)
    _browser.enableGrid = YES; // Whether to allow the viewing of all the photo thumbnails on a grid (defaults to YES)
    _browser.startOnGrid = NO; // Whether to start on the grid of thumbnails instead of the first photo (defaults to NO)
    
    // Optionally set the current visible photo before displaying
    // Manipulate
    [_browser showNextPhotoAnimated:YES];
    [_browser showPreviousPhotoAnimated:YES];
}

#pragma mark - 展开
- (IBAction)unfold:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (_unfoldButton.selected) {
        self.IntroductionLabel.text = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpContent"]];
        _IntroductionLabel.numberOfLines = 0;
        [_IntroductionLabel sizeToFit];
        _unfoldButton.frame = CGRectMake(_unfoldButton.frame.origin.x, _IntroductionLabel.frame.origin.y+_IntroductionLabel.frame.size.height+5, _unfoldButton.frame.size.width, _unfoldButton.frame.size.height);
        _IntroductionView.frame = CGRectMake(0, CGRectGetMinY(_IntroductionView.frame), CGRectGetWidth(_IntroductionView.frame), CGRectGetMaxY(_unfoldButton.frame));
        _evaluationView.frame = CGRectMake(_evaluationView.frame.origin.x, CGRectGetMaxY(_IntroductionView.frame)+10, _evaluationView.frame.size.width, _evaluationView.frame.size.height);
    } else{
        
        _IntroductionLabel.frame = flexibleFrame(CGRectMake(15, 27, 285, 56), NO);
        _IntroductionLabel.numberOfLines = 3;
        self.IntroductionLabel.text = [NSString stringWithFormat:@"%@…",_mstoContent];
        _IntroductionView.frame = flexibleFrame(CGRectMake(0, 696, 320, 100), NO);
        _unfoldButton.frame = flexibleFrame(CGRectMake(132, 83, 56, 19), NO);
        _evaluationView.frame = flexibleFrame(CGRectMake(0, 796, 320, 110), NO);

    }
    _scroview.contentSize = CGSizeMake(0, _evaluationView.frame.origin.y+_evaluationView.frame.size.height);
    

}

#pragma mark - 立即支付
- (IBAction)pay:(id)sender {
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeTeachStoryboard" bundle:nil];
    MakeSureTheOrderViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"MakeSureTheOrder"];
    page.indentDic = _TutorsDetailsDic;
    page.num = _number;
    [[Common getNavigation] pushViewController:page];
}

#pragma mark - 查询家教详情
- (void)TutorsDetails {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    if ([Common getLoginStatus]) {
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    }
    [dic setObject:self.mexpId forKey:@"mexpId"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"lat"] forKey:@"lat"];
    [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"lng"] forKey:@"lng"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_mallExpertDetails withHttpType:@"POST" withTag:JY_JY_mallExpertDetails];
}

#pragma mark - 查询个人展示
- (void)PersonalShow {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:self.mexpId forKey:@"mallExpertId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_mallExpertExtendsList withHttpType:@"POST" withTag:JY_JY_mallExpertExtendsList];
}


#pragma mark -- 添加刷新数据
- (void)addRefreshing{
    self.scroview.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        int64_t delayInSeconds = 8.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [self.scroview.header endRefreshing];
        });
        self.pageNO = 1;
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //请求订单数据
            [self evaluation];
        });
        
    }];
    // 马上进入刷新状态
    [self.scroview.header beginRefreshing];
}
//加载更多数据
- (void)loadMoreData{
    
    if (_tableViewArray.count == _totle) {
        [self.scroview.footer endRefreshing];
    }else{
        self.pageNO = self.pageNO + 1;
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //请求订单数据
            [self evaluation];
        });
    }
    
}

#pragma mark - 查询家教评价
- (void)evaluation {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:self.mexpId forKey:@"mallExpertId"];
    [dic setObject:[NSNumber numberWithInteger:_pageNO] forKey:@"page"];
    [dic setObject:[NSNumber numberWithInteger:PageSize] forKey:@"pageSize"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_mallLecturerCommentList withHttpType:@"POST" withTag:JY_JY_mallLecturerCommentList];
}


- (IBAction)back:(id)sender {
    [_headerScroll removeFromSuperview];
    _headerScroll.delegate = nil;
    _headerScroll.datasource = nil;
    _headerScroll = nil;
    [self backBtn];
}

#pragma mark - 认证资质
- (IBAction)certification:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeTeachStoryboard" bundle:nil];
    CertificationQualificationViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"CertificationQualification"];
    
    page.name = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpName"]];
    page.mallExpertId = self.mexpId;
    [[Common getNavigation] pushViewController:page];
}


#pragma mark   ===== 地图导航
- (IBAction)navHandel:(id)sender {
    NSArray *endPoints;
    NavPointAnnotation * endAnnotation = [[NavPointAnnotation alloc] init];
    CLLocationCoordinate2D coordinate1 = CLLocationCoordinate2DMake(_lat,_lng);
    [endAnnotation setCoordinate:coordinate1];
    endPoints = @[[AMapNaviPoint locationWithLatitude:endAnnotation.coordinate.latitude
                                            longitude:endAnnotation.coordinate.longitude]];
    [self.naviManager calculateDriveRouteWithEndPoints:endPoints
                                             wayPoints:nil
                                       drivingStrategy:0];
    
}



#pragma mark - 分享
- (IBAction)share:(id)sender {
    SharePopView * popView = [[SharePopView alloc]initWithTitles:@[@"微信好友",@"朋友圈",@"QQ空间",@"QQ好友"] complect:^(NSInteger index) {
        if (index == 0) {
            //微信好友
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:_TeachersNameLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
        } else if (index == 1) {
            //朋友圈
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:_TeachersNameLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
            
        } else if (index == 2) {
            //QQ空间
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQzone] content:_TeachersNameLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
        } else if (index == 3) {
            //QQ好友
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQQ] content:_TeachersNameLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
        }
        
    }];
    [popView show];
}

#pragma mark - 收藏
- (IBAction)collection:(id)sender {
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return;
    }
    if (self.collectionButton.selected) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        [dic setObject:self.mexpId forKey:@"mexpId"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_canleMallCollectLecturer withHttpType:@"POST" withTag:JY_JY_canleMallCollectLecturer];
    } else if (!self.collectionButton.selected) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        [dic setObject:self.mexpId forKey:@"mexpId"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_mallCollectLecturer withHttpType:@"POST" withTag:JY_JY_mallCollectLecturer];
    }
}

#pragma mark - 取消分享&&取消收藏
- (IBAction)cancel:(id)sender {
    _BGbutton.hidden = YES;
    _collectionView.hidden = YES;
}

#pragma  mark BestView Delegate Data=source=====================


- (NSInteger)numberOfPages
{
    
    return  self.imageArray.count;
    
}

- (UIView *)pageAtIndex:(NSInteger)index
{
    
    if (self.imageArray.count>0) {
        
        UIImageView  *imageView=[[UIImageView alloc]  initWithFrame: flexibleFrame(CGRectMake(0, 0, 320, 177), NO)];
        [imageView  sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,_imageArray[index]]] placeholderImage:[UIImage imageNamed:@"school5"]];
        return imageView;
    }
    return nil;
}


- (void)didClickPage:(BestScrollView *)csView atIndex:(NSInteger)index
{
}


#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _showArray.count;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(100*VerticalRatio(), 85*VerticalRatio());
    
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    PersonalShowCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionIdentifier forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor whiteColor];
    NSDictionary * dic= _showArray[indexPath.row];
    NSString * image = [NSString stringWithFormat:@"%@",dic[@"meexUrl"]];
    if (image.length>0) {
        [cell.image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
    }
    
    cell.videoImage.hidden = YES;
    NSString * type = [NSString stringWithFormat:@"%@",dic[@"meexType"]];
    if ([type isEqualToString:@"2"]) {
        cell.videoImage.hidden = NO;
    }
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic= _showArray[indexPath.row];
    NSString * type = [NSString stringWithFormat:@"%@",dic[@"meexType"]];
    if ([type isEqualToString:@"2"]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"TeachStoryboard" bundle:nil];
        PersonalShowViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"AgencyVideoShow"];
        page.videoId = [NSString stringWithFormat:@"%@",dic[@"meexId"]];
        [[Common getNavigation] pushViewController:page];
    }
    if ([type isEqualToString:@"1"]) {
        _browser.titleStr = @"个人展示";
        _browser.delegate = self;
        [_browser setCurrentPhotoIndex:0];
        // Present
        UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:_browser];
        [self presentViewController:nc animated:YES completion:nil];
    }
}

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return self.photos.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < self.photos.count) {
        return [self.photos objectAtIndex:index];
    }
    return nil;
}

- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index{
    NSString * str = [NSString stringWithFormat:@"%ld/%ld",index+1,_photos.count];
    return str;
}

#pragma mark - <UITableViewDelegate&&UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

//定义 UITableView cell 的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _tableViewArray.count;
}

//定义 UITableView cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 108*VerticalRatio();
}

//定义 UITableView cell 展示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DrivateTutorDetailTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell= [[DrivateTutorDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
    }
    for (UIView *view in cell.subviews) {
        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    
    NSString *image = [NSString stringWithFormat:@"%@",self.tableViewArray[indexPath.row][@"memberUser"][@"museImage"]];
    if (image && image.length>0 && ![self.tableViewArray[indexPath.row][@"memberUser"][@"mexpImage"] isEqual:[NSNull null]]) {
        [cell.image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
    }
    cell.name.text = [NSString stringWithFormat:@"%@",self.tableViewArray[indexPath.row][@"mallExpert"][@"mexpName"]];
    cell.time.text = [NSString stringWithFormat:@"%@",self.tableViewArray[indexPath.row][@"mlcoCreateTime"]];
    cell.detail.text = [NSString stringWithFormat:@"%@",self.tableViewArray[indexPath.row][@"mlcoContent"]];

    return cell;
}

//定义 UITableView cell 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    [_scroview.header endRefreshing];
    [_scroview.footer endRefreshing];
    if (tag==JY_JY_mallExpertDetails) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            self.TutorsDetailsDic = [NSDictionary dictionary];
            self.TutorsDetailsDic = database[@"result"];
            _lat = [_TutorsDetailsDic[@"mexpLat"] floatValue];
            _lng = [_TutorsDetailsDic[@"mexpLng"] floatValue];
            
            NSString * images = [NSString stringWithFormat:@"%@",_TutorsDetailsDic[@"mexpMultiImage"]];
            images = [images substringToIndex:images.length-1];
            self.imageArray = [[images componentsSeparatedByString:@","]mutableCopy];
            self.headerScroll.delegate=self;
            self.headerScroll.datasource=self;
            [self.headerScroll showImageArray:self.imageArray   withAnimation:YES];

            
            NSString *isCollect = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"isCollect"]];
            if ([isCollect isEqualToString:@"1"]) {
                self.collectionButton.selected = YES;
            } else if ([isCollect isEqualToString:@"2"]) {
                self.collectionButton.selected = NO;
            }
            NSString *image = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpImage"]];
            if (image && image.length>0 && ![self.TutorsDetailsDic[@"mexpImage"] isEqual:[NSNull null]]) {
                [self.TeachersHeaderImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
            }
            self.TeachersNameLabel.text = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpName"]];
            self.TeachersTypeLabel.text = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mallLecturerSubjects"][0][@"mlsuName"]];
            self.moneyLabel.text = [NSString stringWithFormat:@"%@元/小时",self.TutorsDetailsDic[@"mexpPrice"]];
            
            CGFloat distance = [self.TutorsDetailsDic[@"distance"]floatValue];
            NSString *distanceStr;
            if (distance<1000) {
                distanceStr = [NSString stringWithFormat:@" 距离%dm",(NSInteger)distance];
            }else{
                distanceStr = [NSString stringWithFormat:@" 距离%.1fkm",distance/1000];
            }
            [self.distanceButton setTitle:distanceStr forState:UIControlStateNormal];
            
            _totalMoney.text = [NSString stringWithFormat:@"￥%@",self.TutorsDetailsDic[@"mexpPrice"]];
            self.addressLabel.text = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpAddress"]];
            
            
            self.SelfAssessmentLabel.text = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpCommentSelf"]];
            [_SelfAssessmentLabel sizeToFit];
            if (CGRectGetHeight(_SelfAssessmentLabel.frame)>34*VerticalRatio()) {
                self.SelfAssessmentLabel.frame = flexibleFrame(CGRectMake(107, 402, 200, 34), NO);
            }
            //个人擅长
            NSString * Strs = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpGoodsAt"]];
            Strs = [Strs substringToIndex:Strs.length];
            NSArray *StrArray = [NSArray array];
            StrArray = [[Strs componentsSeparatedByString:@","]mutableCopy];
            
            AttributeView *attView = [[AttributeView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 5, 320, 55), NO) title:@"" attributeTexts:StrArray complect:^(NSInteger index) {
                
            }];
            [self.GoodAtView addSubview:attView];
            
            
            NSString *mstoContent = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpContent"]];
            if (mstoContent.length <= 65) {
                self.unfoldButton.hidden = YES;
                _IntroductionLabel.numberOfLines = 0;
                self.IntroductionLabel.text = [NSString stringWithFormat:@"%@",self.TutorsDetailsDic[@"mexpContent"]];
                [_IntroductionLabel sizeToFit];
            } else if (mstoContent.length > 65) {
                self.unfoldButton.hidden = NO;
                
                NSString *string;
                for (int i = 64 ; i >= 0; i--) {
                    string =  [mstoContent substringWithRange:NSMakeRange(i,1)];
                    
                    NSString *str = @"，。、《》？；：’‘“”、|【】{}！@#￥%……&*（）-+=…";
                    
                    if (![str containsString:string]) {
                        _mstoContent = [mstoContent substringToIndex:i];
                        self.IntroductionLabel.text = [NSString stringWithFormat:@"%@…",_mstoContent];
                        break;
                    }
                }
            }
        }
        
    } else if (tag==JY_JY_mallLecturerCommentList) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            dispatch_async(dispatch_get_main_queue(), ^{
                _totle = [database[@"result"][@"total"] integerValue];
                if (_totle > PageSize) {
                    __weak __typeof(self) weakSelf = self;
                    if (!self.scroview.footer) {
                        // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
                        self.scroview.footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
                            [weakSelf loadMoreData];
                        }];
                    }
                }
                if (self.pageNO == 1) {
                    [self.tableViewArray removeAllObjects];
                }
                NSArray *arr = database[@"result"][@"rows"];
                for (id entity in arr) {
                    [self.tableViewArray addObject:entity];
                }
                self.tableView.frame = flexibleFrame(CGRectMake(0, 37, 320, 108*self.tableViewArray.count), NO);
                self.evaluationView.frame = flexibleFrame(CGRectMake(0, 806, 320, 37+self.tableView.frame.size.height/VerticalRatio()), NO);
                _scroview.contentSize = flexibleSize(CGSizeMake(0, 806+self.evaluationView.frame.size.height/VerticalRatio()), NO);
                [self.tableView reloadData];
            });
            
            
        }

    } else if (tag==JY_JY_mallCollectLecturer) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            self.collectionLabel.text = @"收藏成功";
            _collectionView.hidden = NO;
            _BGbutton.hidden = NO;
            self.collectionButton.selected = YES;
        }
        
    } else if (tag==JY_JY_canleMallCollectLecturer) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            self.collectionLabel.text = @"取消收藏";
            _collectionView.hidden = NO;
            _BGbutton.hidden = NO;
            self.collectionButton.selected = NO;
        }
        
    } else if (tag==JY_JY_mallExpertExtendsList) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            _showArray = database[@"result"];
            for (int i = 0; i < _showArray.count; i++) {
                NSString *meexType = [NSString stringWithFormat:@"%@",_showArray[i][@"meexType"]];
                if ([meexType isEqualToString:@"1"]) {
                    NSString *url = [NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,_showArray[i][@"meexUrl"]];
                    MWPhoto * photo = [[MWPhoto alloc]initWithURL:[NSURL URLWithString:url]];
                    [_photos addObject:photo];
                }
            }
            
            [_collectView reloadData];
        }
        
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    [_scroview.header endRefreshing];
    [_scroview.footer endRefreshing];
    //
    [self dismissWaitDialog];
    
    
}


@end
